import wx


"""
根据重构原则，下面这段代码有一点是做到了，就是没有深的嵌套。其它
都没有做到。
为了让你有一个关于如何调整的一个思想，我们将把所有的按钮代码分别
放到各自的方法中。

"""

class RefactorExample(wx.Frame):

    def __init__(self, parent, id):
        super().__init__(parent, id, "Refactor Example", size=(340, 200))

        panel = wx.Panel(self, -1)
        panel.SetBackgroundColour("White")

        firstButton = wx.Button(panel, -1, "FIRST", pos=(5, 0))
        prevButton = wx.Button(panel, -1, "<<PREV", pos=(85, 0))
        nextButton = wx.Button(panel, -1, "NEXT>>", pos=(165, 0))
        lastButton = wx.Button(panel, -1, "LAST", pos=(245, 0))

        self.Bind(wx.EVT_BUTTON, self.OnPrev, prevButton)
        self.Bind(wx.EVT_BUTTON, self.OnNext, nextButton)
        self.Bind(wx.EVT_BUTTON, self.OnFirst, firstButton)
        self.Bind(wx.EVT_BUTTON, self.OnLast, lastButton)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        self.CreateStatusBar()
        menuBar = wx.MenuBar()
        self.SetMenuBar(menuBar)

        fileMenu = wx.Menu()
        openMenuItem = fileMenu.Append(-1, item="&Open", helpString="打开文件")
        fileMenu.AppendSeparator()
        quitMenuItem = fileMenu.Append(-1, item="&Quit", helpString="退出")
        editMenu = wx.Menu()
        copyMenuItem = wx.MenuItem(editMenu, -1, text="Copy", helpString="Copy")
        cutMenuItem = wx.MenuItem(editMenu, -1, text="Cut", helpString="Cut")
        pasteMenuItem = wx.MenuItem(editMenu, -1, text="Paste", helpString="Paste")
        editMenu.Append(copyMenuItem)
        editMenu.AppendSeparator()
        editMenu.Append(cutMenuItem)
        editMenu.AppendSeparator()
        editMenu.Append(pasteMenuItem)
        menuBar.Append(fileMenu, "File")
        menuBar.Append(editMenu, "Edit")

        self.Bind(wx.EVT_MENU, self.OnOpen, openMenuItem)
        self.Bind(wx.EVT_MENU, self.OnCloseWindow, quitMenuItem)
        self.Bind(wx.EVT_MENU, self.OnCopy, copyMenuItem)
        self.Bind(wx.EVT_MENU, self.OnCut, cutMenuItem)
        self.Bind(wx.EVT_MENU, self.OnPaste, pasteMenuItem)

        static1 = wx.StaticText(panel, -1, "Firss Name:", pos=(10, 50))
        static1.SetBackgroundColour("White")
        wx.TextCtrl(panel, -1, "", size=(100, -1), pos=(85, 50))
        static2 = wx.StaticText(panel, -1, "Last Name:", pos=(10, 80))
        static2.SetBackgroundColour("White")
        wx.TextCtrl(panel, -1, "", size=(100, -1), pos=(85, 80))



    # Just grouping the empty event handlers together
    def OnPrev(self, event): pass

    def OnNext(self, event): pass

    def OnLast(self, event): pass

    def OnFirst(self, event): pass

    def OnOpen(self, event): pass

    def OnCopy(self, event): pass

    def OnCut(self, event): pass

    def OnPaste(self, event): pass

    def OnOptions(self, event): pass

    def OnCloseWindow(self, event):
        self.Destroy()




if __name__ == '__main__':
    app = wx.App()

    frame = RefactorExample(None, -1)
    frame.Show()

    app.MainLoop()
